package java学习.实训.day01;

import java.util.Scanner;

/**
 * **************
 * 项目名称: 家庭记账软件 <br/>
 * 文件创建：A6-1913040634-刘世锦 <br/>
 * 创建时间: 2022/6/7 <br/>
 * *************
 */
/*
-----------------家庭收支记账软件-----------------

                   1 收支明细
                   2 登记收入
                   3 登记支出
                   4 退    出

                   请选择(1-4)：
 */
public class Test01 {
    public static int total = 10000;
    public static int index = 0;
    public static int[]  Money = new int[100];
    public static int[] curAccount = new int[100];
    public static String[] info = new String[100];
    public static boolean[] inOrOut = new boolean[100];


    public static void main(String[] args) {
        int  j=0 ;
        Scanner sc=new Scanner(System.in);
        while (j==0){
            print();
            int flag = sc.nextInt();
            choose(flag );
        }

    }

    public static void print(){
        System.out.println("-----------------家庭收支记账软件-----------------");
        System.out.println(" 1 收支明细");
        System.out.println(" 2 登记收入");
        System.out.println("3 登记支出");
        System.out.println("4 退    出");
        System.out.println("请选择(1-4)：");

    }
    public static void choose(int flag   ){
        switch (flag){
            case 1 :
                inAndOutDetails(inOrOut,curAccount,Money,info  );
                break;
            case 2 :
                toIn();
                break;
            case 3 :
                toOut();
                break;
            case 4 :
                Quit();
                break;
            default:System.out.println("选择错误，请重新输入：");

        }

    }

    private static void Quit() {
        Scanner sc=new Scanner(System.in);
        String t;
        char m;
        System.out.println();
        System.out.println("是否选择退出<Y/N>:");
        t=sc.next();//输入字符串
        m=t.charAt(0);//取字符串第一个字符
        if(m=='Y'||m=='y')
            System.exit(0);

    }

    private static void toOut() {
        index++;
        Scanner sc = new Scanner(System.in);
        System.out.println("本次支出金额：" );
        int out = sc.nextInt();
        System.out.println("本次支出说明：" );
        String explan = sc.next();

        Money[index] = out;
        total-=out;
        info[index] = explan;
        curAccount[index] = total;
        inOrOut[index] = false;
    }

    private static void toIn( ) {
        /*
        本次收入金额：1000
        本次收入说明：劳务费
         */
        index++;
        Scanner sc = new Scanner(System.in);
        System.out.println("本次收入金额：" );
        int in = sc.nextInt();
        System.out.println("本次收入说明：" );
        String explan = sc.next();
        Money[index] = in;
        total+=in;
        info[index] = explan;
        curAccount[index] = total;
        inOrOut[index] = true;


    }

    private static void inAndOutDetails(boolean[] inOrOut,int[] curAccount,int[]  Money,String[] info ) {
        System.out.println("--------------------------------当前收支明细--------------------------------------------");
        System.out.println("收支                       账户金额         收支金额                              说 明    ");

        for( int  i=0;i<info.length ;i++){
            if(info[i]!=null) {
                if (inOrOut[i]) {
                    System.out.print("收入                       ");
                    System.out.println(curAccount[i] +"           "+Money[i] + "                                  "+info[i]);
                } else if (!inOrOut[i]) {
                    System.out.print("支出                       ");
                    System.out.println(curAccount[i] +"           "+Money[i] + "                                  "+info[i]);
                }
            }
        }







    }

}
